package cc.autoapi.pucong.auto.flow.core.flow.execNode.entity.api;

import cc.autoapi.pucong.auto.flow.core.flow.execNode.eventBus.PublishMsg;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.selfenum.LogLevelTypeEnum;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.selfenum.RunStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;

@Data
@Accessors(chain = true)
public class ApiHandlerMsgDto extends PublishMsg implements Serializable {

    private static final long serialVersionUID = 1L;

    private String apiId;

    private String instanceId;

    private LogLevelTypeEnum logLevel;

    private RunStatusEnum runStatus;

    private String logContent;

    private Object data;

    private Date createTime;

    private ApiHandlerMsgDto(String apiId, String instanceId, RunStatusEnum runStatus) {
        this.apiId = apiId;
        this.instanceId = instanceId;
        this.runStatus = runStatus;
    }

    private ApiHandlerMsgDto() {
    }

    public static ApiHandlerMsgDto start(String apiId, String instanceId) {
        ApiHandlerMsgDto msg = new ApiHandlerMsgDto(apiId, instanceId, RunStatusEnum.执行中);
        msg.setCreateTime(new Date());
        return msg;
    }

    public static ApiHandlerMsgDto ok(String apiId, String instanceId) {
        ApiHandlerMsgDto msg = new ApiHandlerMsgDto(apiId, instanceId, RunStatusEnum.执行成功);
        msg.setCreateTime(new Date());
        return msg;
    }

    public static ApiHandlerMsgDto error(String apiId, String instanceId, String logContent) {
        ApiHandlerMsgDto msg = new ApiHandlerMsgDto(apiId, instanceId, RunStatusEnum.执行失败);
        msg.setCreateTime(new Date());
        msg.setLogContent(logContent);
        return msg;
    }

    public static ApiHandlerMsgDto log(String apiId, String instanceId, LogLevelTypeEnum logLevel, String logContent) {
        ApiHandlerMsgDto msg = new ApiHandlerMsgDto();
        msg.setApiId(apiId);
        msg.setInstanceId(instanceId);
        msg.setLogLevel(logLevel);
        msg.setLogContent(logContent);
        msg.setCreateTime(new Date());
        return msg;
    }
}
